function ajax(config={}){
	const {url,method="get",data={}} = config;
	if(method.toLowerCase() === "post"){
		if(!config.headers){
			config.headers = {
				"Content-type":"application/json"
			}
		}
		if(data){
			if(data instanceof Object){
				config.body = JSON.stringify(data);
			}
			delete  config.data;
		}
	}
	console.log(url)
	return fetch(url).then(value=>value.json());
}
ajax.get = function(url,config){
	return ajax({
		url,
		// method:"get",
		...config
	})
}

export default ajax;

